﻿using com.nm.library.Excels;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Data;
using System.Linq;

namespace VerticaAPI.Export
{
    [Export(typeof(ExcelImport))]
    public class DWSecondaryData : ExcelImport
    {
        public override ExcelImportType Type => ExcelImportType.SECONDARYDATA;
        public override Dictionary<string, ImportVerify> DictFields => _dictFields;

        private static readonly Dictionary<string, ImportVerify> _dictFields = new List<ImportVerify> {
            new ImportVerify{ ColumnName="日期",FieldName="Stockdate",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,200,true,true)},
            new ImportVerify{ ColumnName="发货仓",FieldName="FHStockName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,200,true,true)},
            new ImportVerify{ ColumnName="店铺",FieldName="ShopName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,200,true,true)},
            new ImportVerify{ ColumnName="货号",FieldName="MaterialID",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,200,true,true)},
            new ImportVerify{ ColumnName="尺码",FieldName="SizeName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,200,true,true)},
            new ImportVerify{ ColumnName="累计销售",FieldName="TotalSaleQty",DataType=typeof(int),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="累计调入",FieldName="TotalMoveQty",DataType=typeof(int),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="生命周期内销售数量",FieldName="lifeTotalSaleQty",DataType=typeof(decimal),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="生命周期内调入数量",FieldName="lifeTotalMoveQty",DataType=typeof(decimal),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="周销售",FieldName="WeekSaleQty",DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true) },
            new ImportVerify{ ColumnName="周调入",FieldName="WeekMoveQty",DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true) },
            new ImportVerify{ ColumnName="有效天数",FieldName="Validdays",DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true) },
            new ImportVerify{ ColumnName="近七天有效日销售量",FieldName="ValidWeekSaleQty",DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true) },
            new ImportVerify{ ColumnName="日均销量",FieldName="ValidWeekAvg",DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true) },
            new ImportVerify{ ColumnName="周期初",FieldName="WeekInitQty" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="上市日期",FieldName="FirstArriveDate" ,DataType=typeof(string),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="上市天数",FieldName="SaleDays" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="计算日均售罄率",FieldName="CalcSaleRate" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="SKU畅滞销状态",FieldName="CZPFlag" ,DataType=typeof(string),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="SKC畅滞销状态",FieldName="SKCCZPFlag" ,DataType=typeof(string),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="销售开始日期",FieldName="SaleBgdate" ,DataType=typeof(string),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="销售结束日期",FieldName="SaleEnddate" ,DataType=typeof(string),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="区间补货系数",FieldName="PeriodSuppleRate" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="是否核心码",FieldName="SizeCoreFlag" ,DataType=typeof(string),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="陈列量",FieldName="DisplayQty" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="理想水位",FieldName="HopeQty" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="目标水位",FieldName="ResultQty" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="补货需求",FieldName="SuppleQty" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="补货结果",FieldName="RobSuppleQty" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="确定补货结果",FieldName="UpdateSuppleQty" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="在仓库存",FieldName="EndQty",DataType=typeof(int),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="在途库存",FieldName="PathQty",DataType=typeof(int),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="订单在途数量",FieldName="OrderPathQty",DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true) },
            new ImportVerify{ ColumnName="可用库存",FieldName="CanUseQty",DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true) },
            new ImportVerify{ ColumnName="两周内是否有调出",FieldName="MoveOutFlagCn",DataType=typeof(string),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true) },
           }.ToDictionary(e => e.ColumnName, e => e);


        public override object SaveImportData(DataTable dt, Dictionary<string, object> extraInfo, int userId)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 获取导出的数据
        /// </summary>
        /// <param name="Keys">查询筛选条件</param>
        /// <returns>Datatable</returns>
        public override DataTable GetExportData(string Keys)
        {
            var db = new DWSuppleAllMessageHandler();
            return db.ExportSecondaryData(Keys);
        }
    }
}
